import {createBrowserRouter,Navigate} from 'react-router-dom'

import Home from '../component/Home'
import Login from '../component/Login/Login'
import Zhuce from '../component/zhuce/Zhuce'
import Updatepass from '../component/updatepassword/Updatepassword'
import Up from '../component/updatepassword/Up'
import Shouye from '../component/Shouye/Shouye'
import Car from '../component/Car/Car'
import Cate from '../component/Cate/Cate'
import My from '../component/My/My'
import Xiang from '../component/Xiang/Xiang'
import User from '../component/User/User'
import Userinfo from '../component/Userinfo/Userinfo'
import Address from '../component/Address/Address'
import Addmap from '../component/Addmap/Addmap'
import Map from '../component/Addmap/Map'
import Update from '../component/Updatepass/Update'
import Mapess from '../component/Mapess/MapContainer'
import Bangzhu from '../component/Bangzhu/Bangzhu'
import Kefu from '../component/Kefu/Chat'
let Authcomponent = (props) => {
    let Com = props.children.type;
    if (sessionStorage.getItem("token")) {
      return <Com></Com>;
    } else {
      return <Navigate to="/" />;
    }
  };

const router = createBrowserRouter([
    {
        path:'/home',
        element:<Authcomponent><Home/></Authcomponent>,
        children:[
            {
                path:'shouye',
                element:<Shouye/>
            },
            {
                path:'cate',
                element:<Cate/>
            },
            {
                path:'car',
                element:<Car/>
            },
            {
                path:'my',
                element:<My/>
            },
            {
                path:'/home',
                element:<Navigate to="shouye"/>
            }
        ]
    },
    {
        path:'/',
        element:<Login/>
    },
    {
        path:'/zhuce',
        element:<Zhuce/>
    },
    {
        path:'/updatepass',
        element:<Updatepass/>
    },
    {
        path:'/up',
        element:<Up/>
    },
    {
        path:'/xiang',
        element:<Xiang/>
    },
    {
        path:'/user',
        element:<User/>
    },
    {
        path:'/userinfo',
        element:<Userinfo/>
    },
    {
        path:'/address',
        element:<Address/>
    },
    {
        path:'/addmap',
        element:<Addmap/>
    },
    {
        path:'/map',
        element:<Map/>
    },
    {
        path:'/update',
        element:<Update/>
    },
    {
        path:'/mapess',
        element:<Mapess/>
    },
    {
        path:'/bangzhu',
        element:<Bangzhu/>
    },
    {
        path:'/kefu',
        element:<Kefu/>
    }
])

export default router